package lanqiao;

import java.util.Scanner;

/**
 * @Project : ProgrammingExercises
 * @Package : LanQiao.PrepareForCompetition
 * @File : Q2122.java
 * @Author : WangRuoyu
 * @Date 2023/3/11 18:28
 */
public class Q2122 {

    static int sum(int x) {
        int res = 0;
        while (x != 0) {
            res += (x % 10);
            x /= 10;
        }
        return res;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int m = scan.nextInt();

        int[] sums = new int[n + 1];
        int[] count = new int[n + 1];
        int tmp = 0;

        for (int i = 1; i <= n; ++i) {
            tmp = sum(i);
            sums[i] = tmp;
            count[tmp]++;
        }

        int value = 1;
        while ((m - count[value]) > 0) {
            m -= count[value];
            value++;
        }

        for (int i = 1; i < sums.length; ++i) {
            if (sums[i] == value) {
                m--;
                if (m == 0) {
                    System.out.println(i);
                    return;
                }
            }
        }
    }
}

